#include "TimeNodSuper.h"

#include "Nod.h"




NodSuper::NodSuper(void): Start(0), End(0)
{
}


NodSuper::~NodSuper(void)
{
}

void NodSuper::AdoptOrphans(const std::vector<Nod*const>& NodVector)
{
	for(std::vector<Nod*>::const_iterator iter= NodVector.begin(); iter!=NodVector.end(); iter++)
		if(! (*iter)->hasParent()) (*iter)->addParent(&Start);
}


void NodSuper::BornCommonChild(const std::vector<Nod*const>& NodVector)
{
	for(std::vector<Nod*>::const_iterator iter= NodVector.begin(); iter!=NodVector.end(); iter++)
		if(! (*iter)->hasChild()) (*iter)->addChild(&Start);
}

void NodSuper::Initialize(const std::vector<Nod*const>& NodVector)
{
	AdoptOrphans(NodVector);
	BornCommonChild(NodVector);



}


//there will be used start nod
Path NodSuper::makePath(const std::vector<Nod* const>& currentNod)
{
	Path currentPath;
	//go through whole vectors
	for(std::vector<Nod*>::const_iterator iter=currentNod.begin(); iter!=currentNod.end(); iter++)
	{
		if (*iter==&End)
		{
			currentPath.addNod(*iter);
			vecOfPaths.push_back(currentPath);
		}
		else
		{
			currentPath=makePath((*iter)->getChildren());
			currentPath.addNod(*iter);
		}
	}

	return currentPath;
}

Path NodSuper::findCriticalPath() const
{
	Path CriticalPath;
	int maxLength=0;
	for (std::vector<const Path>::const_iterator iter=vecOfPaths.begin(); iter!=vecOfPaths.end(); iter++)
		if (iter->getLength()>maxLength) CriticalPath=*iter;
	std::vector<Nod*> NodVec=CriticalPath.getNodVector();

}




int NodSuper::setCriticalPath(const std::vector<Nod*const>&)
{

}